package com.xhwl.logistics.service.cent.server;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.dto.cent.device.DeviceDTO;
import com.xhwl.common.enums.vehicle.DeviceStatusEnum;
import com.xhwl.common.exception.BusinessException;
import com.xhwl.common.query.cent.device.DevicePageQuery;
import com.xhwl.common.query.cent.vehicle.DeviceQuery;
import com.xhwl.logistics.service.cent.IDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;
@Slf4j
//@Service
public class VehicleDeviceFeignServiceImpl implements IVehicleDeviceFeignService {
    @Autowired
    private IDeviceService deviceService;

    @Override
    public Page<DeviceDTO> DevicePage(Short industryId,DeviceQuery deviceQuery ) {
        if (Objects.isNull(deviceQuery.getProjectId())) {
            throw new BusinessException("缺少必要参数：projectId");
        }
        //构建设备中台查询实体
        DevicePageQuery devicePageQuery = new DevicePageQuery();
        devicePageQuery.setProjectIdList(deviceQuery.getProjectId());
        devicePageQuery.setName(deviceQuery.getName());
        DeviceStatusEnum status = deviceQuery.getStatus();
        String orderColumn = deviceQuery.getOrderColumn();
        Boolean orderAsc = deviceQuery.getOrderAsc();
        if (null != orderColumn) {
            devicePageQuery.setOrderColumn(orderColumn);
            devicePageQuery.setOrderAsc(orderAsc);
        }

        if (null != status) {
            devicePageQuery.setOnlineStatus(status.getKey());
        }

        if (null != deviceQuery.getStatus()) {
            devicePageQuery.setOnlineStatus(deviceQuery.getStatus().getKey());
        }
        devicePageQuery.setCurrent(Long.valueOf(deviceQuery.getCurrent()));
        devicePageQuery.setCategoryId(3);
        devicePageQuery.setSize(Long.valueOf(deviceQuery.getPageSize()));
        //devicePageQuery.setQueryLevel(deviceQuery.getQueryLevel());
        //调用设备中台查询车行设备
        Page<DeviceDTO> deviceDTOPage = deviceService.listPageDevice(industryId, devicePageQuery);
        return deviceDTOPage;
    }
}


